Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@universal-packages/directory-traversal
Advanced tools
Simple tool to traverse a directory deeply and get desired info
Sometimes you just need a way to map a directory to either load modules in real time or just get the available files to run a task, directory traversal will map a directory for you and deliver a convenient DirectoryMap
object for you.
npm install @universal-packages/directory-traversal
traverse(locations: String, [options])
The traverse function will go recursively from a root directory until it maps the whole tree, you can execute a callback for every visited directory after being mapped, limit the depth and filter for files you want or you not want to be mapped, returning a DirectoryMap
object
import { traverse } from '@universal-packages/directory-traversal'
const directoryMap = traverse('~/projects')
console.log(directoryMap)
You can modify the behavior of the traverse function by providing options.
callback
Function
A function to call for every mapped directory for you to analyze in place, return false if you want to stop going deeper into that directory.
const directoryMap = traverse('~/projects', {
callback: (directoryMap) => {
if (directoryMap.path.include('homework')) {
return false
}
}
})
fileFilter
(yml | yaml | js | json)[] | Regex
To only include files that satisfies this condition.
maxDepth
Number
To only map files going this level deep.
From the traverse example you will get something like this:
{
"path": "home/projects",
"files": [],
"directories": [
{
"path": "home/projects/universal-directory-traversal",
"files": [
"home/projects/universal-directory-traversal/.editorconfig",
"home/projects/universal-directory-traversal/.gitignore",
"home/projects/universal-directory-traversal/CODE-OF-CONDUCT.md",
"home/projects/universal-directory-traversal/CONTRIBUTING.md",
"home/projects/universal-directory-traversal/LICENSE.md",
"home/projects/universal-directory-traversal/README.md",
"home/projects/universal-directory-traversal/package-lock.json",
"home/projects/universal-directory-traversal/package.json",
"home/projects/universal-directory-traversal/tsconfig.dis.json",
"home/projects/universal-directory-traversal/tsconfig.json"
],
"directories": []
}
]
}
This library is developed in TypeScript and shipped fully typed.
The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.
FAQs
Simple tool to traverse a directory deeply and get desired info
We found that @universal-packages/directory-traversal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.